import { Component } from '@angular/core';
import { ViewController } from 'ionic-angular';

import { NavController, NavParams } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';

@Component({
  selector: 'page-barcodesanner',
  templateUrl: 'barcodescanner.html'
})
export class BarCodeSannerPage {
  selectedItem: any;
  tabBarElement: any;
  barCode: Array<string> = [];
  constructor(public navCtrl: NavController,public viewCtrl: ViewController, public navParams: NavParams,private barcodeScanner: BarcodeScanner,) {
    // If we navigated to this page, we will have an item available as a nav param
    this.selectedItem = navParams.get('item');
    if (document.querySelector('.tabbar')) {
      this.tabBarElement = document.querySelector('.tabbar.show-tabbar');
    }
    
  }

  public usrBarcodeScanner() {
    this.barcodeScanner.scan().then((barcodeData) => {
      this.barCode.unshift(barcodeData.text);
    }, (err) => {
      console.log(err);
      // An error occurred
    });
  }

  ionViewWillEnter() {
    if (this.tabBarElement) {
      this.tabBarElement.style.display = 'none';
    }
  }

  ionViewWillLeave() {
    if (this.tabBarElement) {
      this.tabBarElement.style.display = 'flex';
    }
  }
}